package com.ruoyi.wretchant.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wretchant.domain.MetaAccount;
import com.ruoyi.wretchant.service.IMetaAccountService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账户管理器Controller
 * 
 * @author 简简单单 Online zuozuo
 * @date 2021-08-15
 */
@Controller
@RequestMapping("/wretchant/account")
public class MetaAccountController extends BaseController
{
    private String prefix = "wretchant/account";

    @Autowired
    private IMetaAccountService metaAccountService;

    @RequiresPermissions("wretchant:account:view")
    @GetMapping()
    public String account()
    {
        return prefix + "/account";
    }

    /**
     * 查询账户管理器列表
     */
    @RequiresPermissions("wretchant:account:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MetaAccount metaAccount)
    {
        startPage();
        List<MetaAccount> list = metaAccountService.selectMetaAccountList(metaAccount);
        return getDataTable(list);
    }

    /**
     * 导出账户管理器列表
     */
    @RequiresPermissions("wretchant:account:export")
    @Log(title = "账户管理器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MetaAccount metaAccount)
    {
        List<MetaAccount> list = metaAccountService.selectMetaAccountList(metaAccount);
        ExcelUtil<MetaAccount> util = new ExcelUtil<MetaAccount>(MetaAccount.class);
        return util.exportExcel(list, "账户管理器数据");
    }

    /**
     * 新增账户管理器
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账户管理器
     */
    @RequiresPermissions("wretchant:account:add")
    @Log(title = "账户管理器", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MetaAccount metaAccount)
    {
        return toAjax(metaAccountService.insertMetaAccount(metaAccount));
    }

    /**
     * 修改账户管理器
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MetaAccount metaAccount = metaAccountService.selectMetaAccountById(id);
        mmap.put("metaAccount", metaAccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存账户管理器
     */
    @RequiresPermissions("wretchant:account:edit")
    @Log(title = "账户管理器", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MetaAccount metaAccount)
    {
        return toAjax(metaAccountService.updateMetaAccount(metaAccount));
    }

    /**
     * 删除账户管理器
     */
    @RequiresPermissions("wretchant:account:remove")
    @Log(title = "账户管理器", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(metaAccountService.deleteMetaAccountByIds(ids));
    }
}
